<template>
  <div class="financial-balance">
    <vertical-table :page="pageIndex + '/' + pageCount" class="table" :label-width="215" :labels="labels" :coldata="colData" @lastpage="handleLastPage" @nextpage="handleNextPage" @edit="handleEdit"></vertical-table>
  </div>
</template>

<script>
import { requestAjax } from '../../common.js'
import CONSTANT from '../../constant/constant.js'

export default {
  data() {
    return {
      labels: [
        {
          name: '报表主体',
          label: 'rptMaster'
        },
        {
          name: '报表是否审计',
          label: 'isCheck'
        },
        {
          name: '报表录入人',
          label: 'creatorName'
        },
        {
          name: '报表币种',
          label: 'currencyDesc'
        },
        {
          name: '报表附件',
          label: 'attachment'
        },
        {
          name: '营业总收入',
          label: 'totOperRev'
        },
        {
          name: '其中：营业收入',
          label: 'revenue'
        },
        {
          name: '营业总成本',
          label: 'totOperCost'
        },
        {
          name: '其中：营业成本',
          label: 'salesCost'
        },
        {
          name: '营业税金及附加',
          label: 'taxesSurchargesOps'
        },
        {
          name: '销售费用',
          label: 'operatingExpense'
        },
        {
          name: '管理费用',
          label: 'adminExpense'
        },
        {
          name: '财务费用',
          label: 'financeExpense'
        },
        {
          name: '资产减值损失',
          label: 'impairLossAssets'
        },
        {
          name: '其他业务成本',
          label: 'otherOperExp'
        },
        {
          name: '其他经营净收益',
          label: 'netIncOtherOps'
        },
        {
          name: '公允价值变动净收益',
          label: 'taxesNetGainChgFv'
        },
        {
          name: '投资净收益',
          label: 'investmentIncome'
        },
        {
          name: '对联营企业和合营企业的投资收益',
          label: 'incInvestAssocJvEntp'
        },
        {
          name: '汇兑净收益',
          label: 'netGainFxTrans'
        },
        {
          name: '营业利润',
          label: 'operationProfit'
        },
        {
          name: '营业外收入',
          label: 'nonOperationIncome'
        },
        {
          name: '营业外支出',
          label: 'nonOperationExpense'
        },
        {
          name: '非流动资产处置净损失',
          label: 'netLossDispNoncurAsset'
        },
        {
          name: '利润总额',
          label: 'beforeTaxProfit'
        },
        {
          name: '所得税',
          label: 'tax'
        },
        {
          name: '未确认的投资损失',
          label: 'unconfirmedInvestLossIs'
        },
        {
          name: '净利润',
          label: 'netProfit'
        },
        {
          name: '少数股东权益',
          label: 'minorityIntInc'
        },
        {
          name: '归属母公司股东的净利润',
          label: 'npBelongtoParcomsh'
        }
      ],
      colData: [ {}, {}, {} ],
      pageCount: 1,
      pageIndex: 1
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    loadData(index = 1) {
      const url = CONSTANT.URL.COMPANY.FINANCIALPROFIT
      const params = {
        pageIndex: index,
        pageSize: 3,
        associationId:this.$router.currentRoute.query.userId || 0,
        userId: this.$router.currentRoute.query.id
      }
      requestAjax(url, '{}', params, res => {
        this.pageCount = res.data.pageCount
        this.pageIndex = index
        if (!res.data.bussData) return
        this.colData = res.data.bussData.map(i => {
          return {
            header: {
              text: i.rptDate,
              opText: '编辑',
              opEvent: 'edit'
            },
            data: {
              ...i,
              attachment: i.attachmentId ? {
                text: i.attachmentFile.fileName,
                color: '#0087DC',
                download: i.attachmentFile.fileUrl
              } : {
                text: '上传补充详细附件',
                color: '#ED7018',
                event: 'edit'
              },
              isCheck: i.isCheck == 'y' ? '是' : '否'
            }
          }
        })
        while(this.colData.length < 3) {
          this.colData.push([{header: {}, data: {}}])
        }
      })
    },
    handleLastPage() {
      if (this.pageIndex <= 1) {
        this.$message.warning('已经是第一页了')
      } else {
        this.loadData(this.pageIndex - 1)
      }
    },
    handleNextPage() {
      if (this.pageIndex >= this.pageCount) {
        this.$message.warning('已经是最后一页了')
      } else {
        this.loadData(this.pageIndex + 1)
      }
    },
    handleEdit(item) {
      this.$router.push({
        path: '/partner/financialInfo_v2/financialReportAnalysisEdit', 
        query: {
          id: item.data.id,
          userId: item.data.userId,
          name: this.$route.query.name
        }
      })
    }
  },
  components: {
    "vertical-table": () => import("../common/vertical-table.vue")
  }
}
</script>

<style scoped>
.table {
  margin-right: 40px;
}
</style>
